package com.fly.caihong.activity;

import android.support.v4.app.ActivityCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fly.caihong.R;
import com.fly.caihong.base.BaseActivity;
import com.fly.caihong.model.AttentionMoreItem;
import com.fly.caihong.model.AttentionUserItem;
import com.fly.caihong.utils.DataHandler;
import com.fly.caihong.utils.GlideUtils;
import com.fly.caihong.utils.StatusBarUtils;
import com.fly.caihong.utils.ToastUtils;

import java.util.List;

public class AttentionMoreActivity extends BaseActivity {

    LinearLayout llRecommend, llShuHua;

    @Override
    protected void setStatusBarStyle() {
        StatusBarUtils.setColor(this, ActivityCompat.getColor(this, R.color.theme_bg), 0);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_attention_more;
    }

    @Override
    protected void initViews() {
        super.initViews();
        llRecommend = findViewById(R.id.ll_recommend);
        llShuHua = findViewById(R.id.ll_shuhua);
    }

    @Override
    protected void initData() {
        super.initData();
        AttentionMoreItem attentionMoreItem = DataHandler.convertJsonData("home/attention/search", AttentionMoreItem.class);
        if (attentionMoreItem == null) {
            ToastUtils.showLong("关注更多数据为空");
            return;
        }
        findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        addAttentionItemView(llRecommend, attentionMoreItem.getRecommendUsers());
        addAttentionItemView(llShuHua, attentionMoreItem.getShuHuaUsers());
    }

    private void addAttentionItemView(LinearLayout llLayout, List<AttentionUserItem> userItems) {
        for (AttentionUserItem userItem : userItems) {
            View itemView = LayoutInflater.from(this).inflate(R.layout.layout_attention_more_item, null, false);
            ImageView ivProfile = itemView.findViewById(R.id.iv_profile);
            TextView tvName = itemView.findViewById(R.id.tv_name);
            TextView tvContent = itemView.findViewById(R.id.tv_content);
            TextView tvFans = itemView.findViewById(R.id.tv_fans);
            GlideUtils.loadCircleAvatar(this, ivProfile, userItem.getPhoto());
            tvName.setText(userItem.getNickName());
            tvContent.setText(userItem.getContent());
            tvFans.setText(userItem.getFansCount() + "粉丝");
            llLayout.addView(itemView);
        }
    }

}
